package com.yhp.web;

import com.yhp.bean.Users;
import com.yhp.service.UserService;
import com.yhp.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/tologin"})
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接受参数
        String uname=req.getParameter("uname");
        String upass = req.getParameter("upass");
        //2.调取方法
        UserService userService=new UserServiceImpl();
        Users users = userService.login(uname, upass);
        //3.跳转页面
        if(users==null){
            resp.sendRedirect("/login.jsp");
        }else{
            req.getSession().setAttribute("u1",users);
            resp.sendRedirect("/index.jsp");
        }
    }
}
